package testGameObjects;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import YAPenvironment.YAPconstant;
import YAPserver.gameObjects.Line;
import YAPserver.gameObjects.Point;
import YAPserver.gameObjects.Slider;
import YAPserver.gameObjects.GameWall;

public class TestSlider {
	Slider slider;
	Line boundary;
	
	@Before
	public void setup() throws Exception{
		slider = new Slider(new GameWall(new Point(0,0), new Point(100,0)));
	}
	
	@Test
	public void testToString(){
		slider.setMiddlePoint(new Point(50, 0));
		assertTrue(slider.toString().equals("45	0	55	0"));
	}

	@Test
	public void testTranslateMiddlePoint(){
		
		//result was 10^-16*4 off, which isn't to worry about in the long run - we hope
//		slider.setMiddlePoint(new Point(0, 0));
//		System.out.println(slider.getEndPoint());
//		System.out.println(slider.getStartPoint());
//		assertTrue(slider.getEndPoint().equals(new Point(2, 2)));
//		assertTrue(slider.getStartPoint().equals(new Point(0, 0)));

		slider.setMiddlePoint(new Point(50, 50));
		double length = slider.getLine().getLength();
		String expected = "" + Math.round(50 - length/2.) + "\t50\t" + Math.round(50 + length/2.) + "\t50";
		assertTrue(slider.toString().equals(expected));
	}
	//Code needs changing in slider.java setMiddlePoint isn't needed in gameLogic so that will be changed...
	@Ignore
	@Test
	public void testChangeLength(){
		slider.setLength(50);
		slider.setMiddlePoint(new Point(50, 0));
		System.out.println(slider);
		String expected = "25\t50\t75\t25";
		assertTrue(slider.toString().equals(expected));
	}
	
	@Test
	public void testBoundary(){
		slider.setLength(300);
		double length = slider.getLine().getLength();
		assertTrue(Math.round(length) == 100);
		
		slider.setLength(YAPconstant.C_MINSLIDERSIZE - 0.01);
		length = slider.getLine().getLength();
		assertTrue(Math.round(length) == Math.round(YAPconstant.C_MINSLIDERSIZE));
		
		slider.setLength(YAPconstant.C_MINSLIDERSIZE - 2);
		length = slider.getLine().getLength();
		assertTrue(Math.round(length) == Math.round(YAPconstant.C_MINSLIDERSIZE));
	}
	//Set slider speed hasn't been properly implemented yet
	@Ignore
	@Test
	public void testMovement(){
		slider.setMiddlePoint(new Point(50, 0));
		slider.moveLeft();
		
		String sliderMP = slider.toString();
		System.out.println(slider);
		System.out.println(slider.getMiddlePoint());
		String expected = "0	6	0	8";
		
		assertTrue(sliderMP.equals(expected));
	}
}
